package com.wft;

import java.util.Arrays;

public class Solution776 {
    public static void main(String[] args) {
        String[] a = {"xflbebb","fzqetdc","xktuxef","gfvxchu","goyyhiv"};
        System.out.println(minDeletionSize(a));
    }

    public static int minDeletionSize(String[] A) {
        if (A == null || A.length == 0) {
            return 0;
        }
        int[][] array = new int[A[0].length()][A.length];
        for (int i = 0; i < A[0].toCharArray().length; i++) {
            array[i][0] = A[0].toCharArray()[i];
        }

        for (int i = 1; i < A.length; i++) {
            char[] chars = A[i].toCharArray();
            for (int j = 0; j < chars.length; j++) {
                if (chars[j] >= array[j][i - 1]) {
                    array[j][i] = chars[j];
                }
            }
        }

        int result = 0;
        for (int[] ints : array) {
            for (int i : ints) {
                if(i == 0){
                    result++;
                    break;
                }
            }
        }
        return result;
    }
}
